package y_2025.m04.d18.t01;

// 抽象几何图形类
abstract class Geometry {
    public abstract double getArea();
}

// 圆形类
class Circle extends Geometry {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public double getArea() {
        return Math.PI * radius * radius;
    }
}

// 矩形类
class Rectangle extends Geometry {
    private double length;
    private double width;

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    @Override
    public double getArea() {
        return length * width;
    }
}


// 柱体类
class Pillar {
    private Geometry bottom;  // 底面几何形状
    private double height;    // 柱体高度

    public Pillar(Geometry bottom, double height) {
        this.bottom = bottom;
        this.height = height;
    }

    public double getVolume() {
        return bottom.getArea() * height;
    }
}

// 测试类
public class PillarTest {
    public static void main(String[] args) {
        // 创建不同底面的柱体
        Pillar circlePillar = new Pillar(new Circle(2.0), 5.0);
        Pillar rectanglePillar = new Pillar(new Rectangle(3.0, 4.0), 6.0);

        // 计算并输出体积
        System.out.println("圆形底柱体体积: " + circlePillar.getVolume());
        System.out.println("长方形底柱体体积: " + rectanglePillar.getVolume());
    }
}